package rabbitmq.dwj;

import com.rabbitmq.client.*;

import java.io.IOException;

public class Consumer {

    private final static String queue_name="hello";

    public static void main(String[] args) throws Exception{
        ConnectionFactory factory=new ConnectionFactory();
        factory.setUsername("admin");
        factory.setPort(5672);
        factory.setPassword("123");
        factory.setHost("212.64.48.240");

        Connection connection = factory.newConnection();

        DeliverCallback deliverCallback=(s,delivery) -> {
            String s1 = new String(delivery.getBody());
            System.out.println(s1);
        };

        CancelCallback cancelCallback=(s)->{
            System.out.println("队列已被删除");
        };


        Channel channel = connection.createChannel();
        channel.basicConsume(queue_name,true,deliverCallback,cancelCallback);


    }
}
